//
//  AlbumViewController.m
//  Khmer media
//
//  Created by Rainseylong on 2/11/13.
//  Copyright (c) 2013 imer. All rights reserved.
//

#import "AlbumViewController.h"
#import "PlayMusicViewController.h"
#import "DataManager.h"
#import "ViewFactory.h"
#import "ALBUME.h"


@interface AlbumViewController ()

@end

@implementation AlbumViewController

@synthesize albumDataArray;
@synthesize albumTable;
@synthesize productionId;

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self loadDataFromServer];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

-(void)loadDataFromServer
{
    [ALBUME convertAlbumeToOBjectWithBlock:^(NSArray *albumArray, NSError *error) {
        self.albumDataArray=albumArray;
        [self.albumTable reloadData];
    } withProductID:self.productionId];
}

#pragma mark -
#pragma mark - tableView block

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.albumDataArray count];
}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell=[ViewFactory cellOfKind:@"AlbumCell" forTable:tableView];
    
    UILabel *productionName=(UILabel *)[cell viewWithTag:20];
    UILabel *indexOfAlbum=(UILabel *)[cell viewWithTag:21];
    
    ALBUME *objAlbum=[self.albumDataArray objectAtIndex:indexPath.row];
    productionName.font=[UIFont fontWithName:@"KhmerOSFasthand" size:15];
    productionName.text=objAlbum.albumName;
    
    indexOfAlbum.text=[@(indexPath.row) description];

    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    PlayMusicViewController *playMusicView=[[PlayMusicViewController alloc] initWithNibName:@"PlayMusicViewController" bundle:NULL];
    ALBUME *objAlbume=[self.albumDataArray objectAtIndex:indexPath.row];
    playMusicView.albumId=objAlbume.albumeId.integerValue;
    
    //add albume name
    [DataManager sharedDataManager].albumeName=[NSString stringWithFormat:@"%@/",objAlbume.albumName];
    [self.navigationController pushViewController:playMusicView animated:YES];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60.0;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
